  var zads = (function() {
	return {
		//Init jcal2 calendar
		initCalendar: function() {
			Calendar.setup({
				weekNumbers: true,	//display week number
				inputField: "startdate",	//id of element that is filled by jcal2 
				trigger: "start-button", //id of element that triggers jcal2
				onSelect: function() { //action occurs when user picks a date
					this.hide(); 
				},
				showTime: 24,	//24 hrs mode
				minuteStep: 15, //increasing unit
				dateFormat: "%d/%m/%Y %H:%M"
			});
			Calendar.setup({
				weekNumbers: true,
				inputField: "enddate",
				trigger: "end-button",
				onSelect: function() {
					this.hide();
				},
				showTime: 24,
				minuteStep: 15,
				dateFormat: "%d/%m/%Y %H:%M"
			});
			
			//In our situation, jcal2 triggers are anchor <a>, 
			//thus we must prevent the default action of <a>
			var trigger=document.getElementsByClassName("trigger");
			for (var i=0;i<trigger.length;i++){
				trigger[i].addEventListener("click", function(e){
					e.preventDefault();
				},false);
			}
		},
		
		//Init show more (adding time), unused now
		initMoreButton: function(){
			//Check time function
			var checkTime = function(){
				//You can change to other id which is different than "time"
				var all = document.getElementsByClassName("time");
				for (var i=0;i<all.length;i++){
					if (all[i].value==""){
						return false;
					}
				}
				return true;
			};

		
			var more = document.getElementById("more");
			if(more != null){
				more.addEventListener('click', function(e){
				      e.preventDefault();
				      if (checkTime()==true) {
					      var p = more.parentElement;
					      p = p.parentElement;
					      html = p.getElementsByClassName("form-row-left")[0].getElementsByClassName("row-inner")[0].innerHTML;
					      var newChild = document.createElement('div');
					      newChild.setAttribute('class', 'row-inner');
					      newChild.innerHTML = html;
					      p.getElementsByClassName("form-row-left")[0].appendChild(newChild);
				      }
				      var remove = document.getElementById("remove");
				      if(remove != null){
					remove.style.display = "inline-block";
				      }
			      }, false);
			}			
		}, 
		
		//Parsing a date string to Date object
		parseDate:function(dateString){
			if (dateString=="") {
				return new Date();
			}
			var parts = dateString.split(" ");
			var dateParts = parts[0].split("/");
			var timeParts = parts[1].split(":");
			var date = new Date();
			date.setDate(parseInt(dateParts[0],10));
			date.setMonth(parseInt(dateParts[1],10)-1);
			date.setFullYear(parseInt(dateParts[2],10));
			date.setHours(parseInt(timeParts[0],10));
			date.setMinutes(parseInt(timeParts[1],10));
			return date;
		},
		
		//Parsing a time string to date object
		parseTime:function(timeString){
			if (timeString==""){
				return new Date();
			}
			var timeParts = timeString.split(":");
			var date = new Date();
			date.setHours(parseInt(timeParts[0],10));
			date.setMinutes(parseInt(timeParts[1],10));
			return date;
		},
		
		//Checking a start date and end date (if exists)
		checkDate: function(){
			var sd = document.getElementsByName("startdate");
			var ed = document.getElementsByName("enddate");
			for (var i=0;i<sd.length;i++){
				startDate = zads.parseDate(sd[i].value);
				endDate = zads.parseDate(ed[i].value);
				//You can change here to fit to your DOM
				var p = ed[i].parentElement.parentElement;
				if (endDate!=undefined&&endDate!=NaN&&endDate!=null&&endDate-startDate<=0||sd[i].value==""||ed[i].value==""){
					p.getElementsByClassName("error")[0].style.display="inline";
					return false;
				} else {
					p.getElementsByClassName("error")[0].style.display="none";
					return true;
				} 
			}
		},
		
		//Check a start time and end time (if exists)
		checkTime: function(){
			var sd = document.getElementsByName("startTime");
			var ed = document.getElementsByName("endTime");
			var during = document.getElementById("during");
			var arraySd = new Array();
			var arrayEd = new Array();
			if(during!=undefined && during!=null && during.checked == true){
			  return true;
			}
			// var p = document.getElementById("errorTime");
			if(sd!=undefined && sd!=null && ed != undefined && ed != null){
				var result = true;
			  for (var i=0;i<sd.length;i++){
				  startDate = parseInt(sd[i].value,10);
				  endDate = parseInt(ed[i].value,10);
				
				  //You can change here to fit to your DOM
				 //var p = ed[i].parentElement.parentElement.parentElement;
				//  if( p.getElementsByClassName("error") == null) return true;
				  if (endDate-startDate<0){
					  
					  result = "Exist a pair start time and end time which start time is greater than end time";
					  break;;
				  } 
				  arraySd.push(startDate);
				  arrayEd.push(endDate);
			  }
			  if(result == false){
				 // p.getElementsByClassName("error")[0].style.display="inline";
				  return false;
			  } else{
				   var sum = 0;
				   for(var i = 0; i < arrayEd.length;i++){
				     sum += (arrayEd[i] - arraySd[i]);
				  }
				  if(sum > (24)){ // them6 24 vi co 2 truong hidden khong dung co star = 0, end = 24 (se diable khi post)
				    //p.getElementsByClassName("error")[0].style.display="inline";
				    // p.getElementsByClassName("error")[0].innerHTML = "invalid time in day";
				    return "Summary time running is greater than 24 hours";
				  }
				  // arrayEd[0] va arraySd[0] chua hai gia tri mac dinh 24 va 0 khong tinh
				  for(var i = 1; i < arrayEd.length;i++){
				    for(var j = 0; j < i; j++){
				      var start1 = arraySd[i];
				      var end1 = arrayEd[i];
				      var start2 = arraySd[j];
				      var end2 = arrayEd[j];
				      if(start2 >= start1 && end2 <= end1){
					  result = "Exist a pair start time and end time is overlap with each other";
					  break;
				      } else if(start2 <= start1 && end2 >= end1) {
					  result = "Exist a pair start time and end time is overlap with each other";
					  break;
				      } else if(start2 >= start1 && start2 <= end1) {
					  result = "Exist a pair start time and end time is overlap with each other";
					  break;
				      } else if(end2 <= end1 && end2 >= start1) {
					  result = "Exist a pair start time and end time is overlap with each other";
					  break;
				      }
				    }
				  }
				  //p.getElementsByClassName("error")[0].style.display="none";
			  }
			  return result;
			  
			}
		},
		
		//Validate a wide range of constraints using RegEx
		validate: function(e) {
			var integer=/^-?[0-9]+$/; //Integer: positive and negative. E.g: 10; -6; ...
			var decimal=/^[0-9]+(.[0-9]+)?$/; //Decimal: positive decimal. E.g: 10.6666; ...
			var email=/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/; //Email: 123click.support@hospital
			var dateTime=/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}\s[0-9]{1,2}:[0-9]{1,2}$/;	//Date time: 22/12/2012 14:00
			var positive = /^[1-9][0-9]*$/ //Positive integer
			//var url = /^https?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})#?([\/\w \.-]*)*(\/?\?.*)?$/; //Url: http://hospital/clk?param=...#
			var url = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
			var specialChar = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?";	//Special characters
			var username=/^[a-z]([\._]?[a-z0-9])*$/;	//Username: 123click.support
			
			//Below boolean variables are used to inform invalid fields
			var vNotNull=true;
			var vInteger=true;
			var vDecimal=true;
			var vEmail=true;
			var vDateTime=true;
			var vUrl=true;
			var vLength=true;
			var vNotSpecialChar=true;
			var vNoWhiteSpace = true;
			var vNotHasNumber=true;
			var vPos = true;
			var vUsername = true;
			var vSmaller = true;
			var vCheckUsername = true;
			var vNotExistUsername = true;
			var vCheckUrl = true;
			var vCheckExpandWidth = true;
			var vCheckExpandHeight = true;
			var vBookZone = true;
			var vLinked = true;
			var vmaxShareBanner = true;
			var vDayOfWeek = true;
			
			var className = e.className;
			//This variable is used for displaying error messages. You must change here to fit your DOM
			var p = e.parentElement.parentElement;
						
			//Checking criteria
			if (p.style.display!="none"){
				if (className.indexOf("dayOfWeek")!=-1){
					var valDayOfWeek = document.getElementById("arrDateOfWeek").value;
					if (valDayOfWeek == "") {
					    vDayOfWeek = vDayOfWeek && false;
					} else {
					    try {
						var arrTemp = JSON.parse(valDayOfWeek);
						var isAllEmpty = true;
						for (var i = 0; i < arrTemp.length; i++){
						      if (arrTemp[i].length > 0)
						      {
							    isAllEmpty = false;
							    break;
						      }
						}
						if (isAllEmpty)
						{
						      vDayOfWeek = vDayOfWeek && false;
						}
					    } catch(e) {
						vDayOfWeek = vDayOfWeek && false;
					    }
					}
				}
				
				if (className.indexOf("bookzone")!=-1){
					document.getElementById("perError1").style.display = "none";
					document.getElementById("perError2").style.display = "none";
					var percentage = document.getElementsByName("percentage")[0].value;
					var itemNumber = document.getElementsByName("itemNumber")[0].value;
					var avaiPercent = document.getElementById("prtAvailabe").innerHTML;
					var avaiItemNum = document.getElementById("inumAvailabe").innerHTML;
					avaiPercent = avaiPercent.substr(0, avaiPercent.length - 1);
					avaiPercent = parseInt(avaiPercent, 10);
					percentage  = parseInt(percentage, 10);
					itemNumber  = parseInt(itemNumber, 10);
					avaiItemNum = parseInt(avaiItemNum, 10);
					if (percentage * itemNumber > avaiPercent || itemNumber > avaiItemNum) {
					    vBookZone = vBookZone && false;
					}
				}
				
				if (className.indexOf("lnkpercent")!=-1){
					var avaiPercent = document.getElementById("ava_" + e.id).innerHTML;
					if (parseInt(e.value) > parseInt(avaiPercent) || parseInt(e.value) < 0) {
					    vLinked = vLinked && false;
					}
				}
			  
				if (className.indexOf("notnull")!=-1){
					if (e.value == ""){
						vNotNull=vNotNull&&false;
					} else {
						vNotNull=vNotNull&&true;
					}
				}

				if (className.indexOf("integer")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(integer)){
							vInteger=vInteger&&false;
						} else {
							vInteger=vInteger&&true;
						}
					}
				}
				
				if (className.indexOf("maxShareBanner")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (parseInt(e.value) > 100){
							vmaxShareBanner=vmaxShareBanner&&false;
						} else {
							vmaxShareBanner=vmaxShareBanner&&true;
						}
					}
				}

				if (className.indexOf("decimal")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(decimal)){
							vDecimal=vDecimal&&false;
						} else {
							vDecimal=vDecimal&&true;
						}
					}
				}

				if (className.indexOf("email")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(email)){
							vEmail=vEmail&&false;
						} else {
							vEmail=vEmail&&true;
						}
					}
				}
				
				if (className.indexOf("positive")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(positive)){
							vPos=vPos&&false;
						} else {
							vPos=vPos&&true;
						}
					}
				}

				if (className.indexOf("dateTime")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(dateTime)){
							vDateTime=vDateTime&&false;
						} else {
							vDateTime=vDateTime&&true;
						}
					}
				}

				if (className.indexOf("url")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(url)){
							vUrl=vUrl&&false;
						} else {
							vUrl=vUrl&&true;
						}
					}
				}

				if (className.indexOf("username")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (!e.value.match(username)){
							vUsername=vUsername&&false;
						} else {
							vUsername=vUsername&&true;
						}
					}
				}

				if (className.indexOf("small")!=-1){
					if (e.value!=undefined&&e.value!=""){
						var bigger = document.getElementsByClassName("big")[0];
						if (parseInt(e.value)>parseInt(bigger.value)){
							vSmaller=vSmaller&&false;
						} else {
							vSmaller=vSmaller&&true;
						}
					}
				}
				
				if (className.indexOf("limitlength")!=-1){
					if (e.value!=undefined&&e.value!=""){
						var min = e.getAttribute("minlength")!=undefined && e.getAttribute("minlength")!=""?parseInt(e.getAttribute("minlength")):0;
						var max = e.getAttribute("maxlength")!=undefined && e.getAttribute("maxlength")!=""?parseInt(e.getAttribute("maxlength")):0;
						if (e.value.length<min || e.value.length>max){
							vLength=vLength&&false;
						} else {
							vLength=vLength&&true;
						}
					}
				}
				
				if (className.indexOf("nothasnumber")!=-1){
					if (e.value!=undefined&&e.value!=""){
						if (/\d/.test(e.value)){
							vNotHasNumber=vNotHasNumber&&false;
						} else {
							vNotHasNumber=vNotHasNumber&&true;
						}
					}
				}
				
				if (className.indexOf("notspecialchar")!=-1){
					if (e.value!=undefined&&e.value!=""){
						var isValid = true;
						for (var i = 0; i < e.value.length; i++) {
							if (specialChar.indexOf(e.value.charAt(i)) != -1) {
								isValid = false;
								break;
							}
						}
						if (!isValid){
							vNotSpecialChar=vNotSpecialChar&&false;
						} else {
							vNotSpecialChar=vNotSpecialChar&&true;
						}
					}
				}
				
				if (className.indexOf("nowhitespace")!=-1){
					if (e.value!=undefined&&e.value!=""){
						vNoWhiteSpace = (e.value.indexOf(' ') < 0);						
					}
				}

				if (className.indexOf("expandWidth")!=-1){
					if (!zads.checkExpandWidth(e)){
						vCheckExpandWidth = false;
					} else {
						vCheckExpandWidth = true;
					}
				}

				if (className.indexOf("expandHeight")!=-1){
					if (!zads.checkExpandHeight(e)){
						vCheckExpandHeight = false;
					} else {
						vCheckExpandHeight = true;
					}
				}

				if (className.indexOf("existUsername")!=-1){
					
					zads.ajax("POST", "/async?action=ckuname", {'username':e.value}, 
						function(resp){
							if (resp=="-1"){
								vCheckUsername = false;
								p.getElementsByClassName('exist')[0].style.display="inline";
							} else {
								vCheckUsername = true;
								p.getElementsByClassName('exist')[0].style.display="none";
							}
						}, function(){
							vCheckUsername = false;
						},
						false);
				}
				
				if (className.indexOf("notexistUsername")!=-1){
					
					zads.ajax("POST", "/async?action=ckuname", {'username':e.value}, 
						function(resp){
							if (resp=="-1"){
								vNotExistUsername = true;
								p.getElementsByClassName('notexist')[0].style.display="none";
							} else {
								vNotExistUsername = false;
								p.getElementsByClassName('notexist')[0].style.display="inline";
							}
						}, function(){
							vNotExistUsername = false;
						},
						false);
				}
				
				if (className.indexOf("addedUser")!=-1){
					
					zads.ajax("POST", "/async?action=ckaddeduser", {'username':e.value}, 
						function(resp){
							if (resp=="-1"){
								vCheckUsername = false;
								p.getElementsByClassName('exist')[0].innerHTML = "User has been added"
								p.getElementsByClassName('exist')[0].style.display="inline";
								
							} else if(resp=="-2") {
								vCheckUsername = false;
								p.getElementsByClassName('exist')[0].innerHTML = "Can not add yourself"
								p.getElementsByClassName('exist')[0].style.display="inline";
								
							} else{
								vCheckUsername = true;
								p.getElementsByClassName('exist')[0].style.display="none";
							}
						}, function(){
							vCheckUsername = false;
						},
						false);
				}

				if (className.indexOf("existUrl")!=-1){
					var wid = document.getElementById("wid");
					var val="";
					if (wid!=undefined&&wid!=null){
						val = wid.value;
					}
					zads.ajax("POST", "/async?action=ckurl", {'url':e.value, "wid": val}, 
						function(resp){		
							if (resp=="-1"){
								vCheckUrl = false;
								p.getElementsByClassName('exist')[0].style.display="inline";
							} else {
								vCheckUrl = true;
								p.getElementsByClassName('exist')[0].style.display="none";
							}
						},
						function(){
							vCheckUrl = false;
						}
						,false);
				}
			}


			if(!(vNotNull&&vInteger&&vDecimal&&vEmail&&vDateTime&&vUrl&&vLength&&vNotSpecialChar&&vNoWhiteSpace&&vDayOfWeek&&
				vNotHasNumber&&vPos&&vUsername&&vSmaller&&vCheckExpandHeight&&vCheckExpandWidth&&vBookZone&&vLinked&&vmaxShareBanner))
			{
                            if (className.indexOf("inp-form-error") == -1){
				e.className = className.replace("inp-form", "inp-form-error");
                            }
			}else{
				e.className = className.replace("inp-form-error", "inp-form");
			}
			return vNotNull&&vInteger&&vDecimal&&vEmail&&vDateTime&&vUrl&&vLength&&vNotSpecialChar&&vNoWhiteSpace&&vDayOfWeek&&
			vNotHasNumber&&vPos&&vUsername&&vSmaller&&vCheckUsername&&vCheckUrl&&vCheckExpandHeight&&vCheckExpandWidth&&vNotExistUsername&&vBookZone&&vLinked&&vmaxShareBanner;

		},
		
		//Init validate except for submit button. E.g validating only occurs when "blur" event happens
		initValidateExceptSubmit: function(){
			var elements = document.getElementsByClassName("validate");
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
		},
                        
                initValidate: function(){
			var elements = document.getElementsByClassName("validate");
			var len = document.forms.length;
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
			
			//You can change here if all of your submit buttons have another name.
			var save = document.getElementById('save');
			
			save.addEventListener('click', function(e){
			e.preventDefault();
			var result = true;
				for (var i=0;i<elements.length;i++){
					result = zads.validate(elements[i])&&result;
				}
				if (result==false){
					zm.Boxy.alert("Your given information is not valid","hospital", 5000,{okButton: 'Close'});
					return false;
				} else {
					if (len>1){
						document.getElementById("form-main").submit();
					} else {
						document.forms[0].submit();
					}
			      //return true;
			  }
			  this.setAttribute("disabled", "disabled");
			}, false);
			
		},

		//Fully initiate validating, which is used for every form field except for zSelectorBoxy.
		//In order to execute error-free validating, you must have your fields include "validate" 
		// and validating type you want in its class.   
		initValidateLogin: function(){
			var elements = document.getElementsByClassName("validate");
			var len = document.forms.length;
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
			
			//You can change here if all of your submit buttons have another name.
			var save = document.getElementById('loginSubmit');
			
			save.addEventListener('click', function(e){
                            e.preventDefault();
                            var result = true;
                            for (var i=0;i<elements.length;i++){
                                    result = zads.validate(elements[i])&&result;
                            }
                            if (result==false){
                                    alert("Your given information is not valid","", 5000,{okButton: 'Close'});
                                    return false;
                            } else {
                                var username = document.getElementsByName('username')[0].value;
                                var password = document.getElementsByName('password')[0].value;
                                    $.ajax({
                                        url : baseUrl + "/index/login",
                                        type: "post",
                                        async: false,
                                        data: {
                                            username: username, 
                                            password: password 
                                        }, 
                                        success: function(result){
                                            if (result.error == '1') {
                                                zm.Boxy.alert("Your username and password are incorrect","hospital", 5000,{okButton: 'Close'});
                                            } else {
                                                boxy.hide();
                                                window.location.reload();
                                            }
                                        }
                                    });
                            }
                        }, false);
			
		},
		//For normal use
		initValidateId: function(id){
			var elements = document.getElementsByClassName("validate");
			var len = document.forms.length;
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
			var save = document.getElementById(id);
			
			save.addEventListener('click', function(e){
				e.preventDefault();
				var result = true;
				for (var i=0;i<elements.length;i++){
					result = zads.validate(elements[i])&&result;
				}
				var vdate = zads.checkDate();
				var vtime = zads.checkTime();
				result=result&&vdate&&vtime;
				if (result==false){
					zm.Boxy.alert("Your given information is not valid","hospital", 5000,{okButton: 'Close'});
					return false;
				} else {
					$(".zSelector").each(function(){
						$(this).find('option').each(function(){
						      $(this).attr('selected', 'selected');
						});
					});
					if (len>1){
						document.getElementById("form-main").submit();
					} else {
						document.forms[0].submit();
					}
			      //return true;
				}
				
			  this.setAttribute("disabled", "disabled");
			}, false);
			
		},
		inlineValidate: function(e){
			var elements = document.getElementsByClassName("validate");
			var len = document.forms.length;
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
			var save = document.getElementById('save');
			
			e.preventDefault();
			var result = true;
			for (var i=0;i<elements.length;i++){
				result = zads.validate(elements[i])&&result;
			}
			var vdate = zads.checkDate();
			var vtime = zads.checkTime();
			result=result&&vdate&&vtime;
			if (result==false){
				zm.Boxy.alert("Your given information is not valid","hospital", 5000,{okButton: 'Close'});
				return false;
			} else {
				var oldStartDate = document.getElementById("oldStartDate");
				var oldEndDate = document.getElementById("oldEndDate");
				var newStartDate = document.getElementById("startdate");
				var newEndDate = document.getElementById("enddate");
				
				if (oldStartDate != undefined && oldEndDate != undefined && oldStartDate.value != "" && oldEndDate.value != ""
				    && oldStartDate != undefined && oldEndDate != undefined && oldStartDate.value != "" && oldEndDate.value != "")
				{
				    oldStartDate = oldStartDate.value;
				    oldEndDate = oldEndDate.value;
				    newStartDate = newStartDate.value;
				    newEndDate = newEndDate.value;
				    if (oldStartDate != newStartDate || oldEndDate != newEndDate)
				    {
					  zads.showBoxyEditPercent(newStartDate, newEndDate, "", "");
					  return false;
				    } else {
					  var oldArrDateOfWeek = document.getElementById("oldArrDateOfWeek");
					  if (oldArrDateOfWeek != undefined && oldArrDateOfWeek.value != "") 
					  {
					      var arrDateOfWeek = document.getElementById("arrDateOfWeek");
					      if (arrDateOfWeek != undefined && arrDateOfWeek.value != "") 
					      {
						    if (oldArrDateOfWeek.value.localeCompare(arrDateOfWeek.value) != 0) {
							  zads.showBoxyEditPercent(newStartDate, newEndDate, arrDateOfWeek.value);
							  return false;
						    }
					      }
					  }
				    }
				}
			}
			
			var len = document.forms.length;
			if (len>1){
				document.getElementById("form-main").submit();
			} else {
				document.forms[0].submit();
			}
			var save = document.getElementById('save');
			save.setAttribute("disabled", "disabled");
		  
		},
		showBoxyEditPercent : function (newStartDate, newEndDate, arrDateOfWeek) {
		      
		      var cid = document.getElementById("cid").value;
		      
		      zm.post("/camp?action=relink&act=edit&cid=" + cid,
			{"newStartDate" : newStartDate, "newEndDate" : newEndDate, "arrDateOfWeek" : arrDateOfWeek},
			function(resp) {
			      if (resp != "-1") {
				    uboxy.setTitle("Edit Linked Percent");
				    uboxy.setContent(resp);
				    var elements = document.getElementsByClassName("validate");
				    for (var i=0;i<elements.length;i++){
					    if (elements[i].className.indexOf("dateTime")<0){
						    elements[i].addEventListener('blur', function(){
							    zads.validate(this);
						    }, false);
					    }
				    }
				    
				    var save = document.getElementById('relink');
				    save.addEventListener('click', function(e){
					    e.preventDefault();
					    var result = true;
					    for (var i=0;i<elements.length;i++){
						    result = zads.validate(elements[i])&&result;
					    }
					    if (result==false){
						    zm.Boxy.alert("Your given information is not valid","hospital", 5000,{okButton: 'Close'});
						    return false;
					    } else {
						    var oldPercent = document.getElementById("oldPercent");
						    if (oldPercent != undefined && oldPercent.value != "")
						    {
							var arrOldPercent = oldPercent.value.split(",");
							for (var i = 0; i < arrOldPercent.length; i++) {
							    var key = arrOldPercent[i];
							    var per = document.getElementById(key);
							    if (per != undefined && per.value != "")
							      arrOldPercent[i] += "_" + per.value;
							}
						    }
						    document.getElementById("per").value = arrOldPercent.join();
						    var len = document.forms.length;
						    if (len>1){
							    document.getElementById("form-main").submit();
						    } else {
							    document.forms[0].submit();
						    }
						    var save = document.getElementById('relink');
						    save.setAttribute("disabled", "disabled");
					    }
				    }, false);
				    uboxy.changeSettings({okButton: false, cancelButton: false});
				    uboxy.show();
			      } else {
				    var len = document.forms.length;
				    if (len>1){
					    document.getElementById("form-main").submit();
				    } else {
					    document.forms[0].submit();
				    }
				    var save = document.getElementById('save');
				    save.setAttribute("disabled", "disabled");
			      }
			  
			}
			, function() {

			});
		},
		initValidateWithoutSubmit: function(){
			var elements = document.getElementsByClassName("validate");
			zads.checkDate();
			zads.checkTime();
			for (var i=0;i<elements.length;i++){
				if (elements[i].className.indexOf("dateTime")<0){
					elements[i].addEventListener('blur', function(){
						zads.validate(this);
					}, false);
				}
			}
			
			var save = document.getElementById('save');
			save.addEventListener('click', function(e){
				e.preventDefault();
				var result = true;
				for (var i=0;i<elements.length;i++){
					result = zads.validate(elements[i])&&result;
				}
				if (result==false){
					zm.Boxy.alert("Your given information is not valid","hospital", 5000,{okButton: 'Close'});
					return false;
				} else {
					return true;
				}
			}, false);
		},
		
		//Unused now
		initCheckAll: function(){
			var checkboxes = document.getElementsByName("check");
			var checkAll = document.getElementById("check_parent");
			checkAll.addEventListener('click', function(){
				if (checkAll.checked==true){
					for (var i=0;i<checkboxes.length;i++){
						checkboxes[i].checked = true;
					}
				} else {
					for (var i=0;i<checkboxes.length;i++){
						checkboxes[i].checked = false;
					}
				}
			},false);
		},
		
		//Unused now
		initDeleteButton: function(){
			var anchor = document.getElementsByTagName("a");
			for (var i=0;i<anchor.length;i++){
				if (anchor[i].className.indexOf("delete")>0){
					anchor[i].addEventListener('click', function(e){
						e.preventDefault();
						var h = this.href;
						zads.deleteSelected(h);
					},false);
				}
			}
		},
		commingSoon : function(){
			var boxy = new zm.Boxy({
				title: 'Comming Soon',
				content: "This function will coming soon",
				modal: false,
				okButton: "Close"

			});
			boxy.show();
		},
		//Unused now
		deleteSelected:function(url)
		{
			var obj = zm("INPUT[type='checkbox'][name='check']:checked");					
			var l = new Array();
			obj.each(function (){
				this.checked && l.push(zm(this).val());
			});
			if (l.length>0){
				zmCore.Boxy.confirm("Are you sure you want to delete?",
					function(){					
						
						var list = l.join(',');
						zm.post(url,{list:list},{
							dataType:'json'
						}, function(resp) {
							if(resp.data == "success"){
								zm.Boxy.alert("Delete successfully","hospital", 4000,{okButton: 'Close'});
								var checkboxes = document.getElementsByName("check");
								for (var i=0;i<checkboxes.length;i++){
									checkboxes[i].checked = false;
								}
								var checkAll = document.getElementById("check_parent");
								checkAll.checked = false;
								window.location.reload();
							}
						});
					},{
						title: 'Delete',
						modal: true,
						okButton: "OK",
						cancelButton: "Cancel"                    
					}
					);
			} else {
				zm.Boxy.alert("Your should pick something to delete","hospital", 4000,{okButton: 'Close'});
			}
		},
		predefined:function(){
			var size = document.getElementById("size");
			var width = document.getElementById("width");
			var height = document.getElementById("height");
			var mysize = document.getElementById("mysize");
			var chooseMySize = document.getElementById("chooseMySize");
			var addMySize = document.getElementById("addMySize");
			
			width.setAttribute("disabled", "disabled");
			height.setAttribute("disabled", "disabled");
			if(chooseMySize != undefined) chooseMySize.removeAttribute("disabled");
			if(mysize != undefined && chooseMySize != undefined && size != undefined){
			  if(chooseMySize.checked){
			      mysize.removeAttribute("disabled");
			      size.setAttribute("disabled","disabled");
			  }else{
			    size.removeAttribute("disabled");
			    mysize.setAttribute("disabled","disabled");
			  }
			}
			if(addMySize != undefined) addMySize.style.display="inline";
			width.value=100;
			height.value = 100;
		},
		customer:function(){
			var size = document.getElementById("size");
			var width = document.getElementById("width");
			var height = document.getElementById("height");
			var mysize = document.getElementById("mysize");
			var chooseMySize = document.getElementById("chooseMySize");
			var addMySize = document.getElementById("addMySize");
			size.setAttribute("disabled","disabled");
			width.removeAttribute("disabled");
			height.removeAttribute("disabled");
			if(mysize != undefined) mysize.setAttribute("disabled","disabled");
			if(chooseMySize != undefined) chooseMySize.setAttribute("disabled","disabled");
			if(addMySize != undefined) addMySize.style.display="none";
		},
		changeWebsite : function(a){
			var websiteId = a.value;
			zm.get("/async?action=lbw&wid="+websiteId, {},
				function(resp){
					if (resp!=undefined){
						var layoutSelect = document.getElementById("layoutId");
						layoutSelect.innerHTML=resp;
					}
				}, function(){
					
				});
		},
		changeWebsiteRequire : function(a){
			var websiteId = a.value;
			zm.get("/async?action=lbw&t=0&wid="+websiteId, {},
				function(resp){
					if (resp!=undefined){
						var layoutSelect = document.getElementById("layoutId");
						layoutSelect.innerHTML=resp;
					}
				}, function(){
					
				});
		},
		changeLayout: function(a){
			var layoutId = a.value;
			var websiteId = document.getElementById("websiteId").value;
			window.location = "/zone?wid="+websiteId+"&lid="+layoutId;
		},
		displayFilterSection: function(){
			var filterSection = document.getElementById("filter");
			if (filterSection.style.display=="none"){
				filterSection.style.display="inline";
			} else {
				filterSection.style.display="none";
			}
			return false;
		},
		onCampaignFilter: function(){
			var owner = ((document.getElementById("ownerId").value==undefined)||(document.getElementById("ownerId").value==null))?0:document.getElementById("ownerId").value;
			var website = ((document.getElementById("websiteId").value==undefined)||(document.getElementById("websiteId").value==null))?0:document.getElementById("websiteId").value;
			var state = ((document.getElementById("status").value==undefined)||(document.getElementById("status").value==null))?0:document.getElementById("status").value;
			window.location = "/camp?pid="+owner+"&wid="+website+"&st="+state;
		},
		onCampaignReportFilter: function(){
			var owner = ((document.getElementById("ownerId").value==undefined)||(document.getElementById("ownerId").value==null))?0:document.getElementById("ownerId").value;
			var website = ((document.getElementById("websiteId").value==undefined)||(document.getElementById("websiteId").value==null))?0:document.getElementById("websiteId").value;
			var state = ((document.getElementById("status").value==undefined)||(document.getElementById("status").value==null))?0:document.getElementById("status").value;
			window.location = "/report/camprep?pid="+owner+"&wid="+website+"&st="+state;
		},
		onItemFilter: function(){
			var owner = ((document.getElementById("ownerId").value==undefined)||(document.getElementById("ownerId").value==null))?0:document.getElementById("ownerId").value;
			var website = ((document.getElementById("websiteId").value==undefined)||(document.getElementById("websiteId").value==null))?0:document.getElementById("websiteId").value;
			var campaign = ((document.getElementById("campaignId").value==undefined)||(document.getElementById("campaignId").value==null))?0:document.getElementById("campaignId").value;
			var state = ((document.getElementById("status").value==undefined)||(document.getElementById("status").value==null))?0:document.getElementById("status").value;
			window.location = "/item?pid="+owner+"&wid="+website+"&cid="+campaign+"&st="+state;
		},
		onItemReportFilter: function(){
			var owner = ((document.getElementById("ownerId").value==undefined)||(document.getElementById("ownerId").value==null))?0:document.getElementById("ownerId").value;
			var website = ((document.getElementById("websiteId").value==undefined)||(document.getElementById("websiteId").value==null))?0:document.getElementById("websiteId").value;
			var campaign = ((document.getElementById("campaignId").value==undefined)||(document.getElementById("campaignId").value==null))?0:document.getElementById("campaignId").value;
			var state = ((document.getElementById("status").value==undefined)||(document.getElementById("status").value==null))?0:document.getElementById("status").value;
			window.location = "/report/itemrep?pid="+owner+"&wid="+website+"&cid="+campaign+"&st="+state;
		},
		onSelectOwner: function(a){
			var ownerId = a.value;
			var websiteSelect = document.getElementById("websiteId");
			var campaignSelect = document.getElementById("campaignId");
			if (websiteSelect!=undefined&&websiteSelect!=null){
				zm.get("/async?action=wbp&pid="+ownerId, {},
					function(resp){
						if (resp!=undefined){
							websiteSelect.innerHTML=resp;
						}
					}, function(){
						
					});
			}
			if (campaignSelect!=undefined&&campaignSelect!=null){
				zm.get("/async?action=cbp&pid="+ownerId, {},
					function(resp){
						if (resp!=undefined){
							campaignSelect.innerHTML=resp;
						}
					}, function(){
						
					});
			}
		},
		onFilterWebsiteOwner: function(a){
		  var ownerId = a.value;
		  
			var websiteSelect = document.getElementById("websiteId");
			var campaignSelect = document.getElementById("campaignId");
			if (websiteSelect!=undefined&&websiteSelect!=null){
				zm.get("/async?action=fwo&pid="+ownerId, {},
					function(resp){
						if (resp!=undefined){
							websiteSelect.innerHTML=resp;
						}
					}, function(){
						
					});
			}
		  
		},
		onSelectOwnerForAddingItem: function(a){
			var ownerId = a.value;
			var campaignSelect = document.getElementById("campaign");
			if (campaignSelect!=undefined&&campaignSelect!=null){
				zm.get("/async?action=cbp&t=0&pid="+ownerId, {},
					function(resp){
						if (resp!=undefined){
							campaignSelect.innerHTML=resp;
						}
					}, function(){
						
					});
			}
		},
		onZoneTypeChange: function(a){
			var fixed = document.getElementsByClassName("fixed");
			var floating = document.getElementsByClassName("float");
			var resizable = document.getElementsByClassName("resizable");
			var resizable_inline = document.getElementsByClassName("resizable-inline");
			var video = document.getElementsByClassName("video");
			var enable = function(c){
				for (var i=0;i<fixed.length;i++){
					fixed[i].style.display="none";
				}
				for (var i=0;i<floating.length;i++){
					floating[i].style.display="none";
				}
				for (var i=0;i<resizable.length;i++){
					resizable[i].style.display="none";
				}
				for (var i=0;i<video.length;i++){
					video[i].style.display="none";
				}
				for (var i=0;i<c.length;i++){
					c[i].style.display="block";
				}
			}
			var enableVideo = function(){
				for (var i=0;i<fixed.length;i++){
					fixed[i].style.display="block";
				}
				for (var i=0;i<floating.length;i++){
					floating[i].style.display="none";
				}
				for (var i=0;i<resizable.length;i++){
					resizable[i].style.display="none";
				}
				for (var i=0;i<video.length;i++){
					video[i].style.display="block";
				}
				
			}
			switch (parseInt(a.value)){
				case 1: 
				enable(fixed);
				break;
				case 2: 
				enable(floating);
				break;
				case 3: 
				enable(resizable_inline);
				break;
				case 4: 
				enable(resizable);
				break;
				case 5: 
				enableVideo();
				break;
			}
		},
		initZoneType: function(){
			var a = document.getElementById("zoneType");
			zads.onZoneTypeChange(a);
		},
		onItemTypeChange: function(a){
			var hasMedia = document.getElementsByClassName("hasMedia");
			var targetUrl = document.getElementsByName("targetUrl");
			var targetUrlSpan = document.getElementById("targetUrlSpan");
			var preview = document.getElementById("preview");
			var embeddedHtml = document.getElementById("embeddedHtml");
			var mediaId = document.getElementById("mediaId");
			var origMediaId = document.getElementById("origMediaId");
			var mediaSpan = document.getElementById("mediaIdSpan");
			var embeddedSpan = document.getElementById("embeddedSpan");
			var duration = document.getElementById("duration");
			var extendUrl = document.getElementById("extendUrl");
			var extendUrlSpan = document.getElementById("extendUrlSpan");
			var isVideo = document.getElementById("isVideo");
			
			switch (parseInt(a.value)){
				//Image, Flash and Video
				case 1:
				case 2:
				case 3:
				for (var i=0;i<hasMedia.length;i++){
					hasMedia[i].style.display = "block";
				}
				embeddedSpan.style.display = "none";
				embeddedHtml.removeAttribute("class");
				mediaId.setAttribute("class", "validate notnull");
				origMediaId.setAttribute("class", "validate notnull");
				targetUrl[0].setAttribute("class", "input_css validate notnull url");
				targetUrlSpan.style.display = "inline";
				mediaSpan.style.display = "inline";
				extendUrlSpan.style.display = "none";
				isVideo.style.display = "none";
				extendUrl.setAttribute("class", "input_css validate url");
				$("#uploadMediaRow_preview").css("display","inline");
				$("#uploadMediaRow").css("display","inline");
				break;
				//HTML & Inline HTML
				case 4:
				case 5:
				for (var i=0;i<hasMedia.length;i++){
					hasMedia[i].style.display = "none";
				}
				preview.style.display = "none";
				embeddedSpan.style.display = "inline";
				embeddedHtml.setAttribute("class","validate notnull");
				mediaId.removeAttribute("class");
				origMediaId.removeAttribute("class");
				targetUrl[0].setAttribute("class", "input_css validate url");
				targetUrlSpan.style.display = "none";
				mediaSpan.style.display = "none";
				extendUrlSpan.style.display = "none";
				isVideo.style.display = "none";
				extendUrl.setAttribute("class", "input_css validate url");
				$("#uploadMediaRow_preview").css("display","inline");
				$("#uploadMediaRow").css("display","inline");
				break;
				case 6: // video wrapper
				preview.style.display = "none";
				mediaId.removeAttribute("class");
				origMediaId.removeAttribute("class");
				extendUrlSpan.style.display = "inline";
				isVideo.style.display = "inline";
				extendUrl.setAttribute("class", "input_css validate notnull url");
				targetUrl[0].setAttribute("class", "input_css validate url");
				targetUrlSpan.style.display = "none";
				mediaSpan.style.display = "none";
				$("#uploadMediaRow_preview").css("display","none");
				$("#uploadMediaRow").css("display","none");
				break;
			}
			if (parseInt(a.value) == 3){// video type
				targetUrl[0].setAttribute("class", "input_css validate url");
				targetUrlSpan.style.display = "none";
				duration.style.display = "block";
				var acceptFile = document.getElementsByName("acceptFile");
				for(var i =0; i < acceptFile.length; i++){
					acceptFile[i].innerHTML = "Accept video types: .mp4, .flv, .swf(for VPAID only)";
				}
			} else if(parseInt(a.value) == 6){// video wrapper
				duration.style.display = "none";
				var acceptFile = document.getElementsByName("acceptFile");
				for(var i =0; i < acceptFile.length; i++){
					acceptFile[i].innerHTML = "Accept video types: .mp4, .flv";
				}
			}
			else {
				duration.style.display = "none";
				var acceptFile = document.getElementsByName("acceptFile");
				for(var i =0; i < acceptFile.length; i++){
					acceptFile[i].innerHTML = "Accept file types: .swf, .jpg, .gif, .png";
				}
			}
		},
		initItemType: function(){
			var a = document.getElementById("itemType");
			zads.onItemTypeChange(a);
		},
		checkExpandWidth: function(a){
			var size = document.getElementById("size");
			var expandWidth = parseInt(a.value);
			
			if (size.disabled!=true){
				var parts = size.value.split("x");
				var width = parseInt(parts[0]);
				if (width>expandWidth){
					return false;
				}
			} else {
				var width = parseInt(document.getElementById("width").value);
				if (width>expandWidth){
					return false;
				}
			}
			return true;
		},
		checkExpandHeight: function(a){
			var size = document.getElementById("size");
			var expandHeight = parseInt(a.value);
			if (size.disabled!=true){
				var parts = size.value.split("x");
				var height = parseInt(parts[1]);
				if (height>expandHeight){
					return false;
				}
			} else {
				var height = parseInt(document.getElementById("height").value);
				if (height>expandHeight){
					return false;
				}
			}
			return true;
		},
		
		//AJAX call function
		//(String) method: POST or GET
		//(String) url: URL that you want to call
		//(Array) data: data which is send with ajax
		//(function) successCallback: execute when ajax call is successful
		//(function) failCallback: execute when ajax call is failed
		//(boolean) async: true if ajax call is async, false if ajax call is sync
		ajax: function(method, url, data, successCallback, failCallback, async){
			var ajaxRequest;
			var dataArray = Array();
			var dataString;
			var i=0;

			for (key in data){
				dataArray[i++] = encodeURI(key)+"="+encodeURI(data[key]);
			}

			dataString = dataArray.join("&");

			try {
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				try {
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					return false;
				}
			}

			if (ajaxRequest!=undefined&&ajaxRequest!=null){
				ajaxRequest.onreadystatechange = function(){
					if (ajaxRequest.readyState==4){
						successCallback(ajaxRequest.responseText);

					} else {
						failCallback();
					}
				}
				ajaxRequest.open(method, url, async);
				ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				ajaxRequest.send(dataString);
			} else {
				failCallback();
			}
		},
		renderTemplate: function(src, empty, dest, data){
			//src: id of element contains template section
			//empty: id of element contains content will be filled if data is empty
			//dest: id of element will be filled with renderred template
			//data: JSON string
			var srcElement = document.getElementById(src);
			var emptyElement = document.getElementById(empty);
			var destElement = document.getElementById(dest);
			if (srcElement!=null&&destElement!=null&&emptyElement!=null){
				var template = srcElement.innerHTML;
				var emptyContent = emptyElement.innerHTML;
				var parseData = eval("("+data+")");
				destElement.innerHTML="";
				if (parseData!=null&&parseData.length>0){
					for (var i=0;i<parseData.length;i++){
						var object = parseData[i];
						var renderredString=template;
						for (var field in object){
							var renderredString = renderredString.replace("{"+field+"}", object[field]);
						}
						destElement.innerHTML+=renderredString;
					}
				}
			}	
		},
		onCampaignSearch: function(){
			var zcid = ((document.getElementById("zcid").value==undefined)||(document.getElementById("zcid").value==null))?0:document.getElementById("zcid").value;
			var name = ((document.getElementById("name").value==undefined)||(document.getElementById("name").value==null))?0:document.getElementById("name").value;
			var owner = ((document.getElementById("owner").value==undefined)||(document.getElementById("owner").value==null))?0:document.getElementById("owner").value;
			var desc = ((document.getElementById("desc").value==undefined)||(document.getElementById("desc").value==null))?0:document.getElementById("desc").value;
			window.location = "/camp?cid="+zcid+"&n="+name+"&o="+owner+"&d="+desc;
		},
		onItemSearch: function(){
			var ziid = ((document.getElementById("ziid").value==undefined)||(document.getElementById("ziid").value==null))?0:document.getElementById("ziid").value;
			var name = ((document.getElementById("name").value==undefined)||(document.getElementById("name").value==null))?0:document.getElementById("name").value;
			var desc = ((document.getElementById("desc").value==undefined)||(document.getElementById("desc").value==null))?0:document.getElementById("desc").value;
			var campaign = ((document.getElementById("campaign").value==undefined)||(document.getElementById("campaign").value==null))?0:document.getElementById("campaign").value;
			var url = ((document.getElementById("url").value==undefined)||(document.getElementById("url").value==null))?0:document.getElementById("url").value;
			window.location = "/item?iid="+ziid+"&n="+name+"&d="+desc+"&c="+campaign+"&u"+url;
		},
		onAdPositionChange: function(a){
			var itemPosition = document.getElementById("itemPosition");
			var oldPosition = itemPosition.value!=""?parseInt(itemPosition.value):0;
			if (itemPosition!=null){
				switch (parseInt(a.value)){
					case 0:
					oldPosition = itemPosition.value!=""?parseInt(itemPosition.value):0;
					itemPosition.value=0;
					itemPosition.parentElement.getElementsByClassName('error')[0].style.display="none";
					itemPosition.setAttribute("readonly", "readonly");
					break;

					case 1:
					itemPosition.value=oldPosition>0?oldPosition:5;
					itemPosition.removeAttribute("readonly");
					break;

					case -1:
					oldPosition = itemPosition.value!=""?parseInt(itemPosition.value):0;
					itemPosition.value=-1;
					itemPosition.parentElement.getElementsByClassName('error')[0].style.display="none";
					itemPosition.setAttribute("readonly", "readonly");
					break;
				}
			}
		},
		initAdPosition: function(){
			var adPosition = document.getElementById("adPosition");
			zads.onAdPositionChange(adPosition);
		},
		executeUrl: function(url, success, fail){
			var checkboxes = zm("INPUT[type='checkbox'][class='variable']:checked");
			var sub = zm('.variable');
			var data = new Array();
			var l = new Array();
			checkboxes.each(function (){
				this.checked && l.push(zm(this).val());
			});
			var list = l.join(',');
			
			sub.each(function(){
			  data[this.name] = this.value;
			});
			data['check']=list;
			zads.ajax("POST", url, data, 
			function(){
			    if (success!==undefined){
			      zm.Boxy.alert(success,"123Click", 4000,{okButton: 'Close'});
			    }
			}, function(){
			    if (fail!==undefined){
			      zm.Boxy.alert(fail,"123Click", 4000,{okButton: 'Close'});
			    }
			}, true);
			
		},
		//Init executing for an anchor <a>
		//In order to use this function, you must have at least 1 anchor 
		// with class name "executor" and href attribute points to action url
		initExecutor: function(success, fail){
		  var anchor = document.getElementsByTagName("a");
			for (var i=0;i<anchor.length;i++){
				if (anchor[i].className.indexOf("executor")>0){
					anchor[i].addEventListener('click', function(e){
						e.preventDefault();
						var h = this.href;
						zads.executeUrl(h, success, fail);
					},false);
				}
			}
		},
		
		hide: function() {
			document.getElementById("hideCategory").style.display = "none";
			document.getElementById("campaignContentCate").removeAttribute("isWideNetwork");
			return;
		},
		
		unhide: function() {
			document.getElementById("hideCategory").style.display = "";
			document.getElementById("campaignContentCate").setAttribute("isWideNetwork", "true");
			return;
		},
	    
		hideOrUnhide: function() {
			var wideNetwork = document.getElementById("auto");
			if (wideNetwork.checked == true)
			{
			    zads.hide();
			}
			else
			{
			    zads.unhide();
			}
		},
		
		initSidebar: function() {
			var sideDivs = document.getElementsByClassName("select");
			for (var i = 0; i < sideDivs.length; i++) {
			  if (sideDivs[i].name != "breadscum") {
					sideDivs[i].addEventListener('mouseover', function(){
					    var currents = document.getElementsByClassName("current");
					    if (currents.length == 0)
					    {
						zads.addClass(this, "current");
					    }
					    else
					    {
						for (var j = 0; j < currents.length; j++) {
						    var cur = currents[j];
						    if (cur != this && cur.name != "breadscum")
						    {
							zads.removeClass(cur, "current");
							zads.addClass(this, "current");
						    }
						}
					    }
				    }, false);
				}
			}
		},
		removeClass: function (ele,cls) {
		    if (ele.className != undefined) {
			if (ele.className.indexOf(cls) != -1) {
			    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			    ele.className=ele.className.replace(reg,' ');
			}
		    }
		},
		addClass: function (ele,cls) {
		    ele.className += " "+cls;
		},
		
		initHiddenShare: function(){
		    var hiddenShareButton = document.getElementById("hiddenShareButton");
		    if (hiddenShareButton != undefined && hiddenShareButton != null) { 
			hiddenShareButton.addEventListener('click', function(e){
			      var arrHiddenShare = zm(".slideDown");
			      if (arrHiddenShare != undefined && arrHiddenShare != null && arrHiddenShare.length > 0) {
				  for (var i = 0; i < arrHiddenShare.length; i++) {
				      $(arrHiddenShare[i]).slideUp();
				      arrHiddenShare[i].className = "slideUp";
				      e.currentTarget.className = "icon-9";
				  }
			      } else {
				  arrHiddenShare = zm(".slideUp");
				  if (arrHiddenShare != undefined && arrHiddenShare != null && arrHiddenShare.length > 0) {
				      for (var i = 0; i < arrHiddenShare.length; i++) {
					  $(arrHiddenShare[i]).slideDown();
					  arrHiddenShare[i].className = "slideDown";
					  e.currentTarget.className = "icon-10";
				      }
				  }
			      }
			      return false;
			});
		    }
		},
	    
		getURLParameter: function(name) {
		    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
		},
		
		slideDownSharePage: function(){
		    arrHiddenShare = zm(".slideUp");
		    if (arrHiddenShare != undefined && arrHiddenShare != null && arrHiddenShare.length > 0) {
			for (var i = 0; i < arrHiddenShare.length; i++) {
			    $(arrHiddenShare[i]).slideDown();
			    arrHiddenShare[i].className = "slideDown";
			    document.getElementById("hiddenShareButton").className = "icon-10";
			}
		    }
		},
	    
		changeState: function(o, c, i){
		    var url = o.getAttribute("data");
		    zm.get(url,{
			dataType:'text'
		    }, function(resp) {
			if(resp!= undefined){
			   // boxy.setTitle("Change state for campaign "+c);
			    boxy.setTitle("Change state");
			    boxy.setContent(resp);
			    boxy.changeSettings({okButton:"Change",
				cancelButton: "Cancel",
				onOk:function(){
				    var id = document.getElementById("id");
				    var state = document.getElementsByName("state");
				    var i = 0;
				    for (i=0;i<state.length;i++){
					if (state[i].checked){
					    break;
					}
				    }
				    zm.post(url, {i:id.value, "st":state[i].value}, function(resp){
					window.location.reload();
				    }, function(){
							    
				    });
						    
				}});
			    boxy.show();
			}
		    }, function(){
				    
		    });
		    return false;
		}
	}
})();
